package com.wisdudu.blank.ui.user;

import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.wisdudu.blank.R;
import com.wisdudu.blank.data.Injection;
import com.wisdudu.blank.data.repo.UserRepo;
import com.wisdudu.blank.support.util.AppUtil;
import com.wisdudu.blank.ui.login.LoginActivity;
import com.wisdudu.frame.base.BaseActivity;

public class LogoutActivity extends BaseActivity implements View.OnClickListener {

    protected Context mContext;
    Button btn_isok, btn_cancle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logout);
        mContext = this;
        initView();
    }

    private void initView() {
        btn_isok = (Button) findViewById(R.id.btn_isok);
        btn_isok.setOnClickListener(this);
        btn_cancle = (Button) findViewById(R.id.btn_cancle);
        btn_cancle.setOnClickListener(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_isok:
                /** 修改重新登录BUG*/
                logout();
                break;
            case R.id.btn_cancle:
                /** 修改重新登录BUG*/
                logout();
                break;
        }
    }

    private void logout() {
        UserRepo mUserRepo = Injection.provideUserRepo();
        mUserRepo.logout();
        AppUtil.jumpActivity(this, LoginActivity.class);
//        Intent intent = new Intent();
//        intent.setAction("finishActivity");
//        sendBroadcast(intent);
    }

    @Override
    public void onBackPressed() {
        System.exit(1);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }
}
